using System;
using System.Collections.Generic;
using System.Text;

namespace Zsa.Emulation.PPU
{
    /// <summary>
    /// Bits used for PPU control register one.
    /// </summary>
    [Flags()]
    public enum PPUControlRegisterOneFlags : byte
    {
        #region Name Table Address Bits
        /// <summary>
        /// The name table address is 0x2000.
        /// Bitwise "AND" the NameTableAddressBits and this value to
        /// see if this the current address.
        /// </summary>
        NameTableAddress_0x2000 = 0,

        /// <summary>
        /// The name table address is 0x2400.
        /// Bitwise "AND" the NameTableAddressBits and this value to
        /// see if this the current address.
        /// </summary>
        NameTableAddress_0x2400 = 1,

        /// <summary>
        /// The name table address is 0x2800.
        /// Bitwise "AND" the NameTableAddressBits and this value to
        /// see if this the current address.
        /// </summary>
        NameTableAddress_0x2800 = 2,

        /// <summary>
        /// The name table address is 0x2C00.
        /// Bitwise "AND" the NameTableAddressBits and this value to
        /// see if this the current address.
        /// </summary>
        NameTableAddress_0x2C00 = 3,
        /// <summary>
        /// The name table address. 
        /// 0 ($2000) | 1 ($2400)
        /// 2 ($2800) | 3 ($2C00)
        /// </summary>
        NameTableAddressBits = 3,

        #endregion Name Table Address Bits

        /// <summary>
        /// PPU memory address increments by 32
        /// </summary>
        VerticalWriteFlag = 4,

        /// <summary>
        /// Sprite Pattern Table Address, 1 = $1000, 0 = $0000.
        /// </summary>
        SpritePatternTableAddress = 8,

        /// <summary>
        /// Screen Pattern Table Address, 1 = $1000, 0 = $0000.
        /// </summary>
        BackgroundPatternTableAddress = 16,

        /// <summary>
        /// Sprite Size, 1 = 8x16, 0 = 8x8.
        /// </summary>
        SpriteSize = 32,

        /// <summary>
        /// PPU Master/Slave Mode, not used in NES.
        /// </summary>
        PPUMasterMode = 64,

        /// <summary>
        /// When set vblanks are enabled.
        /// </summary>
        NmiFlag = 128




    }

    /// <summary>
    /// The ppu control register two bits.
    /// </summary>
    [Flags()]
    public enum PPUControlRegisterTwoFlags : byte
    {

        /// <summary>
        /// When set to true the nes is in black and white mode.
        /// </summary>
        MonochromeMode = 1,
        /// <summary>
        /// When set don't show left 8 columns of the screen.
        /// </summary>
        ImageMaskFlags = 2,

        /// <summary>
        /// When set don't show sprites in left 8 columns. 
        /// </summary>
        SpriteMaskFlags = 4,

        /// <summary>
        /// Screen Enable, 1 = show picture, 0 = blank screen.
        /// </summary>
        BackgroundEnabled = 8,

        /// <summary>
        /// When set show sprites.
        /// </summary>
        SpritesEnabled = 16,

        /// <summary>
        /// The bits for the background color.
        /// 0 = black, 1 = blue, 2 = green, 4 = red.
        /// </summary>
        BackgroundColorBits = 32 | 64 | 128,

        /// <summary>
        /// The background color is black.
        /// </summary>
        BackgroundColorBlack = 0,

        /// <summary>
        /// The background color is blue.
        /// </summary>
        BackgroundColorBlue = 32,

        /// <summary>
        /// The background color is green/.
        /// </summary>
        BackgroundColorGreen = 64,

        /// <summary>
        /// The background is red.
        /// </summary>
        BackgroundColorRed = 128,
        

    }

    /// <summary>
    /// The ppu status register.
    /// </summary>
    [Flags()]
    public enum PPUStatusRegister : byte 
    {

        /// <summary>
        /// When set disabled writes to vram.
        /// </summary>
        DisableWrites = 8,

        /// <summary>
        /// Hit Flag, 1 = Sprite refresh has hit sprite #0.
        /// This flag resets to 0 when screen refresh starts.
        /// </summary>
        HitFlag = 1 << 6,

        /// <summary>
        /// VBlank Flag, 1 = PPU is in VBlank state.
        /// This flag resets to 0 when VBlank ends or CPU reads $2002
        /// </summary>
        VBlankFlag = 1 << 7
    }

    /// <summary>
    /// The state of the ppu.
    /// </summary>
    [Flags()]
    public enum PpuState : byte
    {
        /// <summary>
        /// None.
        /// </summary>
        None = 0,

        /// <summary>
        /// Has already written the low byte of the vram address.
        /// This will be reset after the high byte is written or the 
        /// ppu status register is read from.
        /// </summary>
        WritingRAMAddress = 1

    }

    /// <summary>
    /// The flags for a sprite.
    /// </summary>
    [Flags()]
    public enum SpriteFlags : byte
    {
        /// <summary>
        /// The bits used for the sprite color.
        /// </summary>
        ColorBits = 3,

        /// <summary>
        /// The sprite is in the foreground.
        /// </summary>
        ForegroundSprite = 1 << 5,

        /// <summary>
        /// Flip the sprite horizontally.
        /// </summary>
        FlipHorizontally = 1 << 6,

        /// <summary>
        /// Flip the sprite vertically.
        /// </summary>
        FlipVertically = 1 << 7

    }

    /// <summary>
    /// The nes colors.
    /// </summary>
    public enum NesColors : byte
    {
        DarkGrey00 = 0,
        Blue01 = 1,
        Blue02 = 2,
        Blue03 = 3,
        Purple04 = 4,
        Red05 = 5,
        Red06 = 6,
        Red07 = 7,
        Orange08 = 8,
        Green09 = 9,
        Green0A = 0x0A,
        Green0B = 0x0B,
        Blue0C = 0x0C,
        Black0E = 0x0D,
        Black0D = 0x0D,
        Black0F = 0x0F,

        DarkGrey10 = 0x10,
        Blue11 = 0x11,
        Blue12 = 0x12,
        Blue13 = 0x13,
        Purple14 = 0x14,
        Red15 = 0x15,
        Red16 = 0x16,
        Red17 = 0x17,
        Orange18 = 0x18,
        Green19 = 0x19,
        Green1A = 0x1A,
        Green1B = 0x1B,
        Blue1C = 0x1C,
        Black1E = 0x1D,
        Black1D = 0x1D,
        Black1F = 0x1F,


        White20 = 0x20,
        Blue21 = 0x21,
        Blue22 = 0x22,
        Blue23 = 0x23,
        Purple24 = 0x24,
        Red25 = 0x25,
        Red26 = 0x26,
        Red27 = 0x27,
        Orange28 = 0x28,
        Green29 = 0x29,
        Green2A = 0x2A,
        Green2B = 0x2B,
        Blue2C = 0x2C,
        Black2E = 0x2D,
        Black2D = 0x2D,
        Black2F = 0x2F,



        DarkGrey30 = 0x30,
        Blue31 = 0x31,
        Blue32 = 0x32,
        Blue33 = 0x33,
        Purple34 = 0x34,
        Red35 = 0x35,
        Red36 = 0x36,
        Red37 = 0x37,
        Orange38 = 0x38,
        Green39 = 0x39,
        Green3A = 0x3A,
        Green3B = 0x3B,
        Blue3C = 0x3C,
        Black3E = 0x3D,
        Black3D = 0x3D,
        Black3F = 0x3F
    }

    public enum ColorPaletteType : byte
    {
        Sprite,
        Background
    }


}



